﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SIA.HwAccess;

namespace SIA.AutomationControl
{
    public partial class NumericView : UserControl
    {
        private IHwSignal _signal = null;


        public IHwSignal Signal { get { return _signal; } 
            set {
                if (_signal == value) return;
                if (_signal!=null)
                    _signal.ValueChange -= new SignalEvent(_signal_ValueChange);
                _signal = value;
                if (_signal != null)
                {
                    this.label.Text = _signal.Value.ToString();
                    _signal.ValueChange += new SignalEvent(_signal_ValueChange);
                }
            } }

        void _signal_ValueChange(IHwSignal signal)
        {
            if (!this.IsHandleCreated) return;
            this.Invoke(new MethodInvoker(delegate
            {
                this.label.Text = signal.Value.ToString();
            }));
        }

        public NumericView()
        {
            InitializeComponent();

            this.FontChanged += new EventHandler(NumericView_FontChanged);
        }

        void NumericView_FontChanged(object sender, EventArgs e)
        {
            label.Font = this.Font;
        }


    }
}
